Repository navigation
Conversation
Signed-off-by: iamskeole <214513857+iamskeole@users.noreply.github.com>
Strict RFC 8259 parsing (rejects trailing data, leading zeros, deep nesting, bad escapes) with an insertion-ordered object model and typed getters that throw except(). Used by vision-server for its request and response bodies; covered by test-json.cpp. Signed-off-by: iamskeole <214513857+iamskeole@users.noreply.github.com>
POSIX-only HTTP/1.1 server (127.0.0.1 by default) serving all five model families with a minimal JSON API: GET /health POST /sam point/box prompts, all four heads, per-image embed cache POST /birefnet alpha matte POST /depth Depth-Anything-V2 POST /migan inpainting (image + mask) POST /esrgan upscaling (optional tiling) Requests carry base64 images (data: URLs accepted) and support Expect: 100-continue. On a Vulkan backend the --max-arena reservation is probed at boot so the server fails loudly instead of starving other GPU tenants. Covered by test-server.cpp (functional tests that fork the server, poll /health and exercise the routes and error cases). Signed-off-by: iamskeole <214513857+iamskeole@users.noreply.github.com>
This ggml-vulkan allocates one buffer per tensor, so there is no arena to clamp: a graph that does not fit in the remaining device memory fails mid-allocation, inside another client's headroom. check_device_budget() dry-runs the graph allocator (ggml_gallocr_reserve_n_size, no_alloc) to report exactly the buffer the real allocation would create - in-place ops included, which is why summing tensor sizes overcounts - and refuses an over-budget request with 503 and its measured figure, before touching memory. The boot-time arena probe is kept as an early sanity check. Adds a test: a server with a 16 MB budget refuses a MobileSAM request with the measured size instead of attempting the allocation. Signed-off-by: iamskeole <214513857+iamskeole@users.noreply.github.com>
The server's embedding cache captured the encoder's output tensor after the combined encode+predict graph ran. ggml's allocator may reuse a parent's buffer for a later in-place op, so by the time the encoder output was read it could hold intermediate data of the prediction instead. The next cache-hit request then predicted from that garbage: the first request of a server process was correct, every subsequent request on the same image drifted (IoU 0.88 -> 0.29-0.51, never converging, run-dependent). Split the request in two sequential graphs: - phase 1 (encoder only, cache miss): the encoder output is the graph's registered output (compute_graph_output), which also registers the encoder chain and the image input in the graph so the allocator gives them buffers. Nothing can write into the output buffer afterwards, so the post-compute host copy is the true encoder output. - phase 2 (predictor): the embedding is always an input tensor filled from that host copy (a few MB), the prompt is encoded in the same graph; the masks/iou outputs register it as before. With the split, repeated requests for the same image are bit-identical (6/6 point and 3/3 box, CPU and Vulkan) and the per-request VRAM budget drops to max(encoder, predictor) instead of their sum: MobileSAM 200 -> 160 MB (Vulkan), peak 883 -> 694 MiB with all five families resident. Signed-off-by: iamskeole <214513857+iamskeole@users.noreply.github.com>
iamskeole
added a commit
to iamskeole/kokon-ee
that referenced
this pull request
Nov 22, 2026
…dency question recorded Signed-off-by: iamskeole <214513857+iamskeole@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vision-serveris a small HTTP/1.1 server insrc/cli/that serves theproject's GGUF model families over a minimal JSON API. Today the models are
only reachable from the command line (
vision-cli); this adds a small doorfor services that want to run them, with no new dependencies: POSIX sockets,
the project's
util/string.h(gained base64), and a new self-containedutil/json.h.API — images are base64 PNG or JPEG (
data:URLs accepted):GET /healthPOST /sam{"image", "point": {"x","y"} | "box": {"x1","y1","x2","y2"}}{"width","height","iou":[4],"masks":[4 base64 PNGs]}— all four heads, index-stablePOST /birefnet{"image"}{"width","height","image"}— base64 PNG alpha mattePOST /depth{"image"}{"width","height","image"}— base64 PNG depth mapPOST /migan{"image","mask"}{"width","height","image"}— inpainted PNGPOST /esrgan{"image","tile"?}{"width","height","image"}— upscaled PNGDesign notes
Expect: 100-continue; the server answers100 Continuebefore reading the body (covered by a test). Header limit 64 KB, body
limit 64 MB, both answered 4xx.
a single local client; a request queue is a reasonable follow-up.
pixels), so a stream of clicks/boxes on the same image skips TinyViT after
the first. The encoder runs in a graph of its own (the predictor is a
second graph that takes the embedding as an input): in this ggml the
allocator may reuse a parent's buffer for a later in-place op, so the
embedding can only be read back reliably from a graph where it is the
terminal output. With the split, repeated requests for the same image are
bit-identical (verified, CPU and Vulkan).
--max-arena <MB>(default 4096) is a per-requestdevice-memory budget. It is probed at boot (the server fails with an
actionable message if the device cannot provide it), and it is enforced
before every graph allocation: this ggml-vulkan allocates one buffer per
tensor, so a request that does not fit fails mid-allocation inside
another client's headroom. The server instead dry-runs the graph
allocator (
ggml_gallocr_reserve_n_size, no allocation) to report exactlywhat the real allocation would need - in-place ops included - and refuses
an over-budget request with 503 and its measured figure, before touching
memory. The door fails loudly and stays a polite GPU tenant.
POSIX socket APIs, so a Windows port is mechanical.
Tests
tests/test-json.cpp(19): parse/write roundtrips, strict rejections(trailing data, leading zeros, depth limit, bad escapes, unpaired
surrogates), base64 encode/decode.
tests/test-server.cpp(10): forks the real server on a random port, polls/healthfor readiness, then exercises/health,/sampoint and box ona real image, inverted-box → 400, a real
Expect: 100-continueroundtrip,bad JSON → 400, bad image → 400, unknown route → 404, unloaded model →
404, and a server with a 16 MB budget refusing a request it cannot hold,
with the measured size, instead of attempting the allocation.
All five families verified end-to-end over the API on both backends, one
server process, all five models resident:
time - zero VRAM touched): measured per-request graphs 188 MB (SAM), 1332 MB
(BiRefNet lite), 742 MB (Depth V2 Small), 211 MB (MI-GAN), 217 MB (ESRGAN
1024x1024 tile) - all inside the 4096 MB default budget; warm 129 ms (SAM
point, cache hit) / 2.6-5.0 s for the rest. Semantic checks: the matte is
bimodal, the depth map has full dynamic range, inpainting changes only the
masked region, the upscale is 4x.
point/box 110 ms). Per-request budget as dry-run measured by the server:
SAM 160 MB, BiRefNet 1327, Depth 303, MI-GAN 211, ESRGAN 218; peak with all
five resident 694-2052 MiB. SAM per-head IoUs on a fixed reference click
match the CPU server to < 0.01 per head (both backends run the same F16
GGUFs), i.e. the Vulkan path introduces no quality delta.
Verified on Linux x86_64 (Ryzen 5800X,
GGML_NATIVE=OFFSSE4.2/AVX2/F16C,VISP_FMT_LIB=ON,GGML_BACKEND_DL=ON):ctest -C Release— all C++ testspass, including an AddressSanitizer build of the server under a sustained
point/box mix. No Vulkan-specific tests: the project's CI already runs
Vulkan off (llvmpipe is unreliable there) and this PR adds no Vulkan code.
The pre-existing
tests/test_birefnet.py::test_relative_position_indexPython failure isunrelated (it fails on
mainon the same machine).One caveat for consumers: F16 GGUF outputs are not byte-identical to an
FP32/ONNX reference of the same model; compare by selection (IoU / which
head), not by pixels.
Happy to first discuss the shape of this in an issue if you prefer — the
branch is ready either way.